Skip to content

fix(server): an unfinished control sequence no longer delays terminal output - #43

Open
viktorce wants to merge 241 commits into
mainfrom
fix/terminal-unending-string
Open

viktorce wants to merge 241 commits into
mainfrom
fix/terminal-unending-string

Conversation

@viktorce

@viktorce viktorce commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

The server saves a cleaned copy of each terminal's output as its history and sends it to a client that attaches. A client draws that history in a replay. While a control sequence is unfinished, the server holds every piece of PTY output until the sequence ends, so it can keep the sequence whole or strip it. Nothing limited the held text. Output arrived seconds late and server memory grew with every piece. When the sequence ended, the server appended it whole and pushed earlier lines out of history. On main at e37e45fd5b in the web client, seq 1 200000 took 11.87 s after an unfinished CSI, against 0.24 s plain. Closes #37.

Change

Only sanitizeTerminalHistoryChunk and its constants change in apps/server/src/terminal/Manager.ts. I exported sanitizeTerminalHistoryChunk so the new test can call it. This PR adds a limit on held text for each kind of sequence. The limits count UTF-16 code units and apply only when a piece ends inside a sequence. Web and Android draw with Ghostty's libghostty-vt terminal emulator, pinned to 3ff6d08f in native/libghostty-vt/VERSION. The limits below follow what it does.

  • OSC, DCS, PM, and APC strings. The limit is 524,288, equal to DEFAULT_MAX_TERMINAL_BUFFER_BYTES. Clients keep 512 KiB and drop any sequence their trim cuts through, so none can replay a longer string whole.
  • CSI. The limit is 4,096. CSIs carry no payload, and pinned libghostty-vt does not run a CSI with more than 24 parameters. The server also rescans a held CSI from the start on every piece.
  • Escape sequences. The limit is 5, for ESC and four intermediates, bytes 0x20 to 0x2F before the final byte. Past that limit, the server holds the first five code units and drops later intermediates. Ghostty ignores later intermediates at Parser.zig:313-321, so five code units replay the same as the whole sequence.

Past a string or CSI limit, the server holds only the introducer and drops the rest. The introducer is the two characters that open a string or a CSI, like ESC ]. The sequence stays unfinished, and history resumes only after its own end arrives. That stops late output and unbounded memory. For a string, it also keeps earlier history intact. For a CSI, history still receives executed controls like line feeds as they arrive, so earlier lines still scroll out just as they do on the live screen.

The first drop of a string or a CSI writes one ST, ESC \, the string terminator, to history. That closes any earlier unfinished sequence, such as a title cut short by the dropped sequence's ESC. In ground state, outside any sequence, ST does nothing. Later pieces of the same sequence write no further ST.

The server stays inside an oversized string because Ghostty prints no oversized string as text. Ending it early would replay output the live screen never showed. Between 524,288 code units and Ghostty's own size caps, Ghostty's parser still accepts some strings that history now drops. No client can replay a string longer than 512 KiB whole.

The four evidence comments on this PR, each headed "Evidence for the PR description, part N of 4", hold the evidence behind this description. Two of the strings Ghostty's parser still accepts are an OSC 52 and a DCS under 1 MiB. The first evidence comment explains why those two strings have no effect on the screen in pinned libghostty-vt on web and Android.

Costs I accept:

  • Dropped CSIs. Ghostty still runs a dropped CSI with at most 24 parameters at its final byte, while history omits it. That can lose a mode like bracketed paste on a replay. I accept this because an oversized CSI can be a query such as ESC [, 20,000 zeros, and 6n, which replay would answer.
  • Replay replies. The strip rules remove terminal queries from history so replays stay quiet. When a query they miss sits unfinished in history before a dropped sequence, the drop ST closes it. Replay then answers it just as the live terminal answered it at the same point. Two of the 76 test streams in Replay comparison below show this new reply. On main, the same replay sends nothing. Web drops replay replies at apps/web/src/terminal/ghostty/core.ts:429. Android forwards them to the program's input at T3TerminalView.kt:398 and :459.
  • Copying below 524,288. Each piece still makes the server copy held strings below the limit. For 2 MiB of plain output in 64-character pieces after an unfinished OSC, this PR takes 191 ms, against 7 ms plain and 3,068 ms on main. Peak held text drops from 2,097,161 code units on main to 524,233.

Scope

This is a bug fix for #37. The fix solves one problem, the same unlimited hold across all six sequence kinds. It changes only server history parsing and adds one paragraph to docs/internals/terminal-runtime.md, with no contract, client, provider, or locale changes.

Upstream PRs 29604 and 30479 end an unfinished string at the next ESC. This bug happens when no ESC follows.

On 2026-11-20, the upstream project had 2,418 open pull requests, and 21 of them change apps/server/src/terminal/Manager.ts. I read what each of those 21 pull requests changes in that file, and none limits the held text. Only one of the 21, upstream PR 28840, adds code to sanitizeTerminalHistoryChunk that main does not already have. In that function, it reads the shell's OSC 133;D command-finished mark and adds a commandExitCode field to every return statement. Those return statements include the three this PR replaces, so the later of the two pull requests to land needs a small manual merge in that function and in the lines directly above it. Upstream PR 28840 targets a feature branch and not main, so that merge comes up only when its branch lands. Eight other open pull requests, each of about 34,800 files, are too large for GitHub to list in full, and I did not check them.

Left out:

  • Mid-sequence attach. A client attaching while a sequence is unfinished still starts in ground state and prints output history lacks, as on main.
  • Strip rules. They stay as they are on main, and the first evidence comment lists the queries they miss.
  • Six unfixed, unfiled defects on main, in the first evidence comment.
  • Holding strings below 524,288 as a list of pieces to remove the copying cost.
  • Returning history to ground state between sequences by closing strings cut short by ESC and dropping abandoned escape sequences. That would remove the drop ST and defects 3 and 4 in the first evidence comment.
  • Newer Ghostty C1 rules. The sanitizer follows the 3ff6d08f pin until native/libghostty-vt/VERSION moves, detailed in the second fold.

Verification

Reviewers found this bug during code review of another terminal fix. No user reported it. I reproduced it on purpose in a real shell and the web client.

Test. stops holding a control sequence that outgrows its limit in Manager.test.ts runs nine rows. All 122 tests in the file pass. On main with only export added, it fails with DCS, split code point: expected 526343 to be less than or equal to 4. The test is larger than the fewest rows that fail on main, on purpose, so all 61 hand-made mutations of the fix fail it. Every row and check except escape ends uniquely catches at least one.

Web client. vp run scenarios:prove fails on main and passes on 1662c3c7d6 for CSI and OSC, one run each. Each time below measures from the Enter key to the first frame that shows DONE in the web client. The recorded commands print DONE in black on green so the page can detect the frame. The recording scenario in the fourth evidence comment and the timing probes in the third compare elapsed times, so I did not commit them.

Typed into the terminal main This PR
seq 1 200000; printf 'DONE\n' 0.24 s 0.22 s
printf '\033['; seq 1 200000; printf 'mDONE\n' 11.87 s 0.21 s
seq 1 2000000; printf 'DONE\n' 2.21 s 2.22 s
printf '\033]0;stuck'; seq 1 2000000; printf '\007DONE\n' 22.66 s 2.23 s

Each video shows main on top and this PR below, with a stopwatch that the recording adds.

CSI:

unfinished-csi-before-after.mp4

OSC:

unfinished-osc-before-after.mp4

Runtime transcript. On a real /bin/sh PTY with no browser, I timed from writing each command until DONE reached the manager's listeners. printf '\033['; seq 1 200000; printf 'mDONE\n' fell from 11,528 ms on main to 178 ms. printf '\033]0;stuck'; seq 1 3000000; printf '\007DONE\n' fell from 51,344 ms on main to 2,685 ms, against 2,599 ms plain.

Replay comparison. I compared 76 test streams as live output against history replays in the web client's Ghostty core. With this PR, 51 match and 25 differ for reasons I expected, with none unexpected. On main, 19 differ, 1 unexpectedly. The 25 are 8 dropped CSIs Ghostty ran, 3 split surrogate pairs a real PTY never sends, and 14 other streams that differ on main too. The two streams with the new reply are among those 14, and on main they differ because the replay swallows the text after the query. Two of main's 19 now match, and the 8 dropped CSIs are new.

Checks. vp run check:changed passes format, lint, knip, graphql, typecheck of 3 packages, and tests of 2 files.

Not checked. iOS uses a separate Ghostty fork rather than the 3ff6d08f pin, and I did not read it. I did not test newer Ghostty or run desktop, Android, or iOS. Web timings are one dev-stack run each.

Evidence. The first evidence comment has Ghostty notes, replay output, defects on main, and strip rules. The second has mutations, timings, memory, and real PTY logs. The third has probes and scripts. The fourth has the recording scenario.

The whole window when each run ended
main This PR
CSI Base e37e45fd5b, CSI This PR, CSI
OSC Base e37e45fd5b, OSC This PR, OSC
What Ghostty has changed since the pin

The 3ff6d08f pin is a Ghostty commit from 2026-07-07, and Ghostty has since changed two behaviours the server models. Ghostty PR 14016, merged 2026-08-25, makes bytes 0x80 to 0xFF payload inside a DCS, so a code point with a C1 byte no longer ends one. Ghostty PR 14023, merged 2026-08-26, drops U+0080 to U+009F in ground state, where the pin prints them. On Ghostty main of 2026-11-19, a C1 byte still ends a CSI, a PM or APC string, and a DCS header. The sanitizer and two new test rows, DCS, split code point and DCS opened by U+0090, match the pin.

Code by Claude Fable 5.2 and Claude Opus 5.5 in Claude Code. Description written by Gemini 4 Neon in Antigravity and reviewed by Claude Fable 5.2. Driven from T3 Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the vouch:trusted Author is trusted by repo permissions or the VOUCHED list. label Nov 19, 2026
@viktorce
viktorce force-pushed the fix/terminal-unending-string branch from b153d3e to fa0eb18 Compare November 19, 2026 23:59
juliusmarminge and others added 3 commits November 19, 2026 16:07
…ain (pingdotgg#37419)

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
@viktorce
viktorce force-pushed the fix/terminal-unending-string branch from fa0eb18 to 2174d60 Compare November 20, 2026 00:41
@viktorce

viktorce commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner Author

Evidence for the PR description, part 1 of 4. None of this is committed.

What the Ghostty source does at the pin

I read libghostty-vt at 3ff6d08f, the pin in native/libghostty-vt/VERSION, which web and Android use. The iOS framework is built from a fork at another revision, which I did not read.

  • OSC (src/terminal/osc.zig). A fixed 2048-byte buffer. On overflow the parser state becomes invalid and "any further input" is discarded. end() returns null for invalid, so nothing is dispatched. OSC 52, 66, 72 and 5522 use a growing buffer instead. OSC 66 caps its payload at 4096.
  • DCS (src/terminal/dcs.zig). max_bytes is 1 MiB. Past it the handler discards its state and ignores the rest.
  • APC (src/terminal/apc.zig). Kitty graphics buffer up to 65 MiB and the glyph protocol 1 MiB. Past its cap a command is ignored, and so is any other APC. PM uses the same parser state and handler.
  • CSI and ESC (src/terminal/Parser.zig). No size exit at all. collect ignores every intermediate past the fourth (MAX_INTERMEDIATE is 4, Parser.zig:313-321), and the parser waits for the final byte. That is why cutting a held escape sequence to the ESC and four intermediates replays the same. At the final byte a CSI with 24 or more parameter separators, so more than 24 parameters, is not dispatched at all (Parser.zig:369). A run of digits is one parameter, so Ghostty still runs a CSI with one long run of digits.
  • Controls inside a string (src/terminal/parse_table.zig). In osc_string the parser ignores 0x00 to 0x06, 0x08 to 0x17, 0x19 and 0x1C to 0x1F. BEL ends the OSC, CAN and SUB cancel it, ESC leaves it, and DEL is payload. In dcs_entry, dcs_param and dcs_intermediate it ignores 0x00 to 0x17, 0x19, 0x1C to 0x1F and DEL. src/terminal/stream_terminal.zig:283-288 ignores dcs_hook, dcs_put and dcs_unhook, so libghostty-vt answers no DCS query.

In every case the parser stays in the sequence until a terminator. Size never ends it. So libghostty prints none of an oversized string as text. The parser still accepts some strings up to its own caps, such as an OSC 52 or a DCS under 1 MiB. src/terminal/stream_terminal.zig:285-293 gives OSC 52 and every DCS no effect, so on web and Android history drops nothing the screen used.

Live output against a replay of the history, 76 streams in the real Ghostty core

The server half runs the real sanitizer over each stream. The Ghostty half feeds the stream to one core, the web client's wasm, as live output and the server's history to a second core as a replay. It compares the visible rows, the red attribute, the cursor position, the full scrollback text and what the client would send to the program: a paste of one\ntwo, application cursor keys and a focus report. Any reply a replay sends also counts as a difference, because the program already got the live one. The stream ESC with intermediates past a client's cut replays what a client keeps on attach, retainedTerminalHistory(history, 512 * 1024).

most held is the longest held text the sanitizer returned for that stream. The oversized CSI and ESC streams arrive in 16 KiB pieces, so they pass their limit in the first piece. live, pair joined feeds the stream to the core as one write. The harness counts a cell as red when its red channel is more than 50 above its green, because Ghostty draws SGR 31 as (204, 102, 102). base replay replies is what the same core sends on a replay of the e37e45fd5b history for the same stream. The summary splits the replays that reply by whether the e37e45fd5b replay replies too.

With this PR, 51 streams match and 25 differ as expected. No stream differs unexpectedly.

  • The dropped CSI exception, 8 streams. At its final byte Ghostty runs an oversized CSI with at most 24 parameters, and history leaves it out. CSI, oversized, then SGR 31 shows red in red live and not on replay. CSI, oversized, then erase display erases the live screen, and the replay still shows before. The three sets streams turn on bracketed paste, application cursor keys and focus reporting live and not on replay, so the client sends a paste, a cursor key and a focus report differently. The limit counts every character held inside the CSI, so three streams reach it without long parameters. CSI, oversized by line feeds, then SGR 31 is ESC[, 5,000 line feeds and 31mred. CSI, oversized by DEL, sets bracketed paste is ESC[?2004, 5,000 DEL characters and h. CSI, seq output, then cursor up is ESC[, 123\r\n 2,000 times and ATOP: the live cursor goes up to the top row, the replay cursor stays at the bottom. Ghostty does not dispatch a CSI with more than 24 parameters at all, so the three 3001 parameters streams match.
  • A split surrogate pair, 3 streams. DCS, split code point after the limit, CSI, split code point after the limit and DCS inside the limit, split code point split U+2081C across two chunks. Its last UTF-8 byte, 0x9C, ends a CSI or a DCS. History joins the pair, as e37e45fd5b already does below the limit. The web core encodes each write on its own, so the live core gets two U+FFFD instead and the sequence stays open. Fed the same stream as one write, the core shows what the replay shows. node-pty decodes its output with a StringDecoder, which never splits a code point, so a real PTY does not produce these chunks.
  • Streams that differ on e37e45fd5b too, 14 streams. Five show base defects from the list below, and nine show queries the strip rules miss.

12 replays send a reply. For 10 of them the e37e45fd5b replay replies too: ESC with an intermediate, then U+009B and 6n, ESC, LF, then [6n, SOS read as an escape sequence, then U+009B and 6n, and seven queries the strip rules miss, each terminated or followed by a kept sequence. The other 2 reply only with this PR: OSC 11 query behind a LF, cut short by an oversized query and OSC 4 query, cut short by an oversized query. The ST closes the open query, and the live terminal answered it at the same point. On e37e45fd5b the same replay sends nothing and swallows after. No replay replies only on e37e45fd5b.

Defects that exist on e37e45fd5b too

This PR does not fix these, and no issue is filed for them yet.

  1. ESC, optional intermediates, then U+009B and 6n, or U+009A. History keeps it, and the replay answers. Stream ESC with an intermediate, then U+009B and 6n.
  2. ESC, LF, then [6n. The sanitizer saves [6n as text. The emulator runs the LF inside the escape sequence and reads [6n as a query, live and on replay. Stream ESC, LF, then [6n.
  3. ESC, intermediates, then ESC[6n and text. History strips the query, so on replay the first character of the text ends the escape sequence. Stream ESC with intermediates, then 6n.
  4. ESC]0;one, then ESC[6n, then text. History keeps the title with no terminator and strips the query, so a replay swallows the text. It is the gap the ST closes after a dropped sequence, here after a stripped one. Stream title cut short by a stripped query.
  5. ESC X, SOS. The sanitizer reads it as a two-character escape sequence and keeps what follows as text. The emulator opens a string, where a U+009B starts a CSI, so ESC X, U+009B and 6n reply live and on replay. Stream SOS read as an escape sequence, then U+009B and 6n.
  6. A DCS held under the limit, with a surrogate pair split across chunks, replays differently. Stream DCS inside the limit, split code point.

Defects 3 and 4 go away if history always returns to ground state between sequences, the follow-up in the description.

Queries the strip rules miss

The strip rules know OSC 10, 11 and 12 when the content starts with the colour number and then ? or rgb:. This PR leaves them as they are on e37e45fd5b. Ghostty answers these queries, which the rules miss:

  • an OSC 10, 11 or 12 query behind a control. libghostty ignores most C0 controls inside an OSC, so ESC ] LF 11;? BEL is a colour query to it;
  • a query in a later colour slot, ESC]10;#ffffff;? BEL or ESC]10;red;? BEL, which set the foreground and query the background;
  • OSC 4, ESC]4;1;? BEL;
  • OSC 21, ESC]21;foreground=? BEL;
  • CSI 21 t, which reports the title.

Terminated, each replies on the replay here and on e37e45fd5b. The strip rules decide that, not the ST:

## OSC 11 query behind a LF
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss an OSC 11 query behind a control, on the base too

## OSC 10 query in the second colour slot
stream 30 chars, history 30 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss a query in a later colour slot, on the base too

## OSC 10 query after a colour name
stream 26 chars, history 26 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [0,1] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [0,1] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss a query in a later colour slot, on the base too

## OSC 4 query
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
base replay replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover OSC 4, on the base too

## OSC 21 query
stream 33 chars, history 33 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
base replay replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover OSC 21, on the base too

## CSI 21 t title report
stream 20 chars, history 20 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]l\u001b\\"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]l\u001b\\"]
base replay replies ["\u001b]l\u001b\\"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover CSI 21 t, on the base too

The ST closes whatever history left open. If that is a query string the rules miss, the replay answers it. The live terminal answered it at the same point. Left open before an oversized query, OSC 4 and the OSC 11 behind a LF reply on replay with this PR:

## OSC 11 query behind a LF, cut short by an oversized query
stream 20026 chars, history 24 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u001b\\","\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u001b\\"]
base replay replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the ST closes an OSC 11 query the strip rules miss, so it replies. The base swallows after

## OSC 4 query, cut short by an oversized query
stream 5026 chars, history 24 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\","\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
base replay replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the ST closes an OSC 4 query the strip rules do not cover, so it replies. The base swallows after

On e37e45fd5b the same replays send nothing and swallow after:

## OSC 11 query behind a LF, cut short by an oversized query
stream 20026 chars, history 22 chars, most held 20002 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u001b\\","\u001b[2;1R"]
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 1
DIFFERENT, expected: the ST closes an OSC 11 query the strip rules miss, so it replies. The base swallows after

## OSC 4 query, cut short by an oversized query
stream 5026 chars, history 22 chars, most held 5002 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\","\u001b[2;1R"]
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 1
DIFFERENT, expected: the ST closes an OSC 4 query the strip rules do not cover, so it replies. The base swallows after

A kept sequence's ESC closes the query the same way, here and on e37e45fd5b:

## OSC 4 query, cut short by a kept sequence
stream 25 chars, history 25 chars, most held 7 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
replay screen: ["before","red"] cursor 0,2 red rows [1] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
base replay replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the kept sequence's ESC closes an OSC 4 query the strip rules do not cover, on the base too

A stripped string writes nothing. History keeps the OSC 11 behind a LF, so its ESC closes a title or a DCS left open before it. Both streams match, here and on e37e45fd5b:

## title cut short by an OSC 11 behind a LF
stream 31 chars, history 31 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS cut short by an OSC 11 behind a LF, then U+009A
stream 28 chars, history 28 chars, most held 3 chars
live screen:   ["before","�after"] cursor 0,2 red rows [] replies []
replay screen: ["before","�after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

Stripping that OSC would leave history open instead, as title cut short by a stripped query shows for a stripped CSI query, defect 4 above. So widening the rules needs an ST after a stripped sequence, which changes the history of every stripped query. That is one follow-up, and this PR leaves the rules alone.

The DCS twin, ESC P LF $ q m ESC \, gets no reply live, because libghostty-vt answers no DCS query. Left open before an oversized query, it matches with this PR and swallows after on e37e45fd5b:

## DCS query behind a LF, cut short by an oversized query
stream 20025 chars, history 23 chars, most held 6 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

The web client drops replies while it replays history, because resetAndWrite in apps/web/src/terminal/ghostty/core.ts detaches the PTY writer around the replay write, at line 429. Android forwards them to the program's input, T3TerminalView.kt:398 and :459. That is why the strip rules matter.

Full output with this PR
## OSC, never ends
stream 680023 chars, history 10 chars, most held 507913 chars
live screen:   ["before"] cursor 0,1 red rows [] replies []
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 1
SAME

## OSC, ends with BEL
stream 680025 chars, history 17 chars, most held 507913 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC, ST split across chunks
stream 680026 chars, history 17 chars, most held 507913 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC, ends with CAN
stream 680025 chars, history 17 chars, most held 507913 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC, cut short by a new sequence
stream 680029 chars, history 22 chars, most held 507913 chars
live screen:   ["before","after"] cursor 0,2 red rows [1] replies []
replay screen: ["before","after"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC 11 query, oversized
stream 680022 chars, history 17 chars, most held 507910 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC 52, oversized
stream 680023 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC inside the limit
stream 34025 chars, history 34025 chars, most held 34009 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS, never ends
stream 680021 chars, history 10 chars, most held 507911 chars
live screen:   ["before"] cursor 0,1 red rows [] replies []
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 1
SAME

## DCS, ends with ST
stream 680024 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS, ends at a C1 byte in text
stream 680023 chars, history 19 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,3 red rows [] replies []
replay screen: ["before","after"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## DCS, BEL is payload
stream 680039 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## PM, ends with ST
stream 680024 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## APC, ends with ST
stream 680024 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## APC kitty image, oversized
stream 680030 chars, history 17 chars, most held 507917 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI, never ends
stream 17017 chars, history 2012 chars, most held 3 chars
live screen:   [] cursor 0,7 red rows [] replies []
replay screen: [] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 1
SAME

## CSI, ends with a letter
stream 17018 chars, history 2017 chars, most held 3 chars
live screen:   ["after"] cursor 0,7 red rows [] replies []
replay screen: ["after"] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1002, replay 1002
SAME

## CSI, a few line feeds then a letter
stream 10022 chars, history 21 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,4 red rows [] replies []
replay screen: ["before","after"] cursor 0,4 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 4, replay 4
SAME

## CSI, ends with CAN
stream 17018 chars, history 2017 chars, most held 3 chars
live screen:   ["after"] cursor 0,7 red rows [] replies []
replay screen: ["after"] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1002, replay 1002
SAME

## CSI, cut short by a new sequence
stream 17022 chars, history 2022 chars, most held 3 chars
live screen:   ["after"] cursor 0,7 red rows [6] replies []
replay screen: ["after"] cursor 0,7 red rows [6] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1002, replay 1002
SAME

## CSI, oversized device status query
stream 20019 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI inside the limit
stream 18 chars, history 18 chars, most held 4 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with intermediates, oversized
stream 20017 chars, history 21 chars, most held 5 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with intermediates, never ends
stream 20009 chars, history 8 chars, most held 5 chars
live screen:   ["before"] cursor 0,1 red rows [] replies []
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 1
SAME

## DCS, ends at U+009B then 6n
stream 680025 chars, history 17 chars, most held 507911 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS, split code point after the limit
stream 680024 chars, history 17 chars, most held 507911 chars
live screen:   ["before"] cursor 0,1 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
live, pair joined: ["before","after"] cursor 0,2, same as replay
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 2
DIFFERENT, expected: split pair: the web core encodes each write alone

## CSI, split code point after the limit
stream 17019 chars, history 2017 chars, most held 4 chars
live screen:   ["fter"] cursor 0,7 red rows [] replies []
replay screen: ["after"] cursor 0,7 red rows [] replies []
live, pair joined: ["after"] cursor 0,7, same as replay
input: same, paste "one\rtwo"
scrollback lines: live 1002, replay 1002
DIFFERENT, expected: split pair: the web core encodes each write alone

## DCS inside the limit, split code point
stream 34024 chars, history 34024 chars, most held 34008 chars
live screen:   ["before"] cursor 0,1 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
live, pair joined: ["before","after"] cursor 0,2, same as replay
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 2
DIFFERENT, expected: split pair: the web core encodes each write alone, on the base too

## CSI, oversized, then SGR 31
stream 20018 chars, history 15 chars, most held 3 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, oversized, then erase display
stream 20019 chars, history 17 chars, most held 3 chars
live screen:   ["after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## ESC with an intermediate, then U+009B and 6n
stream 20 chars, history 20 chars, most held 2 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
base replay replies ["\u001b[2;1R"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the replay replies, on the base too

## ESC cut short, then an oversized OSC, then U+009A
stream 524311 chars, history 20 chars, most held 3 chars
live screen:   ["before","�after"] cursor 0,2 red rows [] replies []
replay screen: ["before","�after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC cut short, then an oversized OSC, then U+009B and 6n
stream 524313 chars, history 22 chars, most held 3 chars
live screen:   ["before","�6nafter"] cursor 0,2 red rows [] replies []
replay screen: ["before","�6nafter"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC cut short, then an oversized OSC, then text
stream 524310 chars, history 19 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## title cut short by an oversized OSC
stream 714036 chars, history 34030 chars, most held 507911 chars
live screen:   ["before","after","more"] cursor 0,3 red rows [] replies []
replay screen: ["before","after","more"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## title cut short by an oversized CSI
stream 17031 chars, history 2030 chars, most held 7 chars
live screen:   ["after","more"] cursor 0,7 red rows [] replies []
replay screen: ["after","more"] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1003, replay 1003
SAME

## charset designation cut short by an oversized OSC
stream 680031 chars, history 25 chars, most held 507911 chars
live screen:   ["before","after","more"] cursor 0,3 red rows [] replies []
replay screen: ["before","after","more"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## CSI, oversized, sets bracketed paste
stream 5023 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: live {"paste":"\u001b[200~one\ntwo\u001b[201~","cursorKeys":false,"focus":""}, replay {"paste":"one\rtwo","cursorKeys":false,"focus":""}
scrollback lines: live 2, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, oversized, sets application cursor keys
stream 5020 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: live {"paste":"one\rtwo","cursorKeys":true,"focus":""}, replay {"paste":"one\rtwo","cursorKeys":false,"focus":""}
scrollback lines: live 2, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, oversized, sets focus reporting
stream 5023 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: live {"paste":"one\rtwo","cursorKeys":false,"focus":"\u001b[I"}, replay {"paste":"one\rtwo","cursorKeys":false,"focus":""}
scrollback lines: live 2, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, oversized with 3001 parameters, then SGR 31
stream 6018 chars, history 15 chars, most held 3 chars
live screen:   ["before","red"] cursor 0,2 red rows [] replies []
replay screen: ["before","red"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI, oversized with 3001 parameters, then erase display
stream 6019 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI, oversized with 3001 parameters, then 6n
stream 6019 chars, history 17 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI inside the limit with 24 parameters, SGR 31
stream 64 chars, history 64 chars, most held 0 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## CSI inside the limit with 25 parameters, SGR 31
stream 66 chars, history 66 chars, most held 0 chars
live screen:   ["before","red"] cursor 0,2 red rows [] replies []
replay screen: ["before","red"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## title cut short by a stripped query
stream 26 chars, history 22 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before"] cursor 0,1 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 1
DIFFERENT, expected: a stripped sequence after an open title, on the base too

## ESC with intermediates past a client's cut
stream 600030 chars, history 29 chars, most held 5 chars
live screen:   ["one","two","three","four","five"] cursor 0,5 red rows [] replies []
replay screen: ["one","two","three","four","five"] cursor 0,5 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 5, replay 5
SAME

## ESC with intermediates past the limit, then a final byte
stream 20023 chars, history 26 chars, most held 5 chars
live screen:   ["before","lqk","after"] cursor 0,3 red rows [] replies []
replay screen: ["before","lqk","after"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## ESC with intermediates past the limit, then SGR 31
stream 20019 chars, history 23 chars, most held 5 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with intermediates past the limit, then LF and text
stream 20017 chars, history 21 chars, most held 5 chars
live screen:   ["before","fter"] cursor 0,3 red rows [] replies []
replay screen: ["before","fter"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## ESC with intermediates, then 6n
stream 22 chars, history 18 chars, most held 3 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","fter"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: a stripped query after open intermediates, on the base too

## ESC, LF, then [6n
stream 20 chars, history 20 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,3 red rows [] replies ["\u001b[3;1R"]
replay screen: ["before","after"] cursor 0,3 red rows [] replies ["\u001b[3;1R"]
base replay replies ["\u001b[3;1R"]
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
DIFFERENT, expected: the replay replies, on the base too

## CSI, oversized by line feeds, then SGR 31
stream 5018 chars, history 5015 chars, most held 3 chars
live screen:   ["red"] cursor 0,7 red rows [6] replies []
replay screen: ["red"] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 5002, replay 5002
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, seq output, then cursor up
stream 10016 chars, history 4015 chars, most held 3 chars
live screen:   ["TOP"] cursor 0,1 red rows [] replies []
replay screen: ["TOP"] cursor 0,7 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 1995, replay 2002
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## CSI, oversized by DEL, sets bracketed paste
stream 5023 chars, history 17 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: live {"paste":"\u001b[200~one\ntwo\u001b[201~","cursorKeys":false,"focus":""}, replay {"paste":"one\rtwo","cursorKeys":false,"focus":""}
scrollback lines: live 2, replay 2
DIFFERENT, expected: libghostty runs the oversized CSI at its final byte, history drops it

## ESC with 4 intermediates, then a final byte
stream 21 chars, history 21 chars, most held 5 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with 4 intermediates, then SGR 31
stream 23 chars, history 23 chars, most held 5 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with 4 intermediates, then LF and text
stream 21 chars, history 21 chars, most held 5 chars
live screen:   ["before","fter"] cursor 0,3 red rows [] replies []
replay screen: ["before","fter"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## ESC with 5 intermediates, then a final byte
stream 22 chars, history 21 chars, most held 5 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with 5 intermediates, then SGR 31
stream 24 chars, history 23 chars, most held 5 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies []
replay screen: ["before","red"] cursor 0,2 red rows [1] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## ESC with 5 intermediates, then LF and text
stream 22 chars, history 21 chars, most held 5 chars
live screen:   ["before","fter"] cursor 0,3 red rows [] replies []
replay screen: ["before","fter"] cursor 0,3 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 3, replay 3
SAME

## OSC 11 query behind a LF
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss an OSC 11 query behind a control, on the base too

## OSC 11 query behind a LF, cut short by an oversized query
stream 20026 chars, history 24 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u001b\\","\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u001b\\"]
base replay replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the ST closes an OSC 11 query the strip rules miss, so it replies. The base swallows after

## OSC 11 query with DEL inside
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS query behind a LF
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS query behind a LF, cut short by an oversized query
stream 20025 chars, history 23 chars, most held 6 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC 4 query
stream 23 chars, history 23 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
base replay replies ["\u001b]4;1;rgb:cccc/6666/6666\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover OSC 4, on the base too

## OSC 4 query, cut short by an oversized query
stream 5026 chars, history 24 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\","\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
base replay replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the ST closes an OSC 4 query the strip rules do not cover, so it replies. The base swallows after

## OSC 4 query, cut short by a kept sequence
stream 25 chars, history 25 chars, most held 7 chars
live screen:   ["before","red"] cursor 0,2 red rows [1] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
replay screen: ["before","red"] cursor 0,2 red rows [1] replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
base replay replies ["\u001b]4;1;rgb:cccc/6666/6666\u001b\\"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the kept sequence's ESC closes an OSC 4 query the strip rules do not cover, on the base too

## SOS read as an escape sequence, then U+009B and 6n
stream 20 chars, history 20 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b[2;1R"]
base replay replies ["\u001b[2;1R"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the sanitizer reads ESC X as an escape sequence and keeps the query, on the base too

## title cut short by an OSC 11 behind a LF
stream 31 chars, history 31 chars, most held 7 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies []
replay screen: ["before","after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## DCS cut short by an OSC 11 behind a LF, then U+009A
stream 28 chars, history 28 chars, most held 3 chars
live screen:   ["before","�after"] cursor 0,2 red rows [] replies []
replay screen: ["before","�after"] cursor 0,2 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
SAME

## OSC 10 query in the second colour slot
stream 30 chars, history 30 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss a query in a later colour slot, on the base too

## OSC 10 query after a colour name
stream 26 chars, history 26 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [0,1] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [0,1] replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
base replay replies ["\u001b]11;rgb:0000/0000/0000\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules miss a query in a later colour slot, on the base too

## OSC 21 query
stream 33 chars, history 33 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
base replay replies ["\u001b]21;foreground=rgb:ff/ff/ff\u0007"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover OSC 21, on the base too

## CSI 21 t title report
stream 20 chars, history 20 chars, most held 0 chars
live screen:   ["before","after"] cursor 0,2 red rows [] replies ["\u001b]l\u001b\\"]
replay screen: ["before","after"] cursor 0,2 red rows [] replies ["\u001b]l\u001b\\"]
base replay replies ["\u001b]l\u001b\\"]
input: same, paste "one\rtwo"
scrollback lines: live 2, replay 2
DIFFERENT, expected: the strip rules do not cover CSI 21 t, on the base too

76 streams
unexpected differences: 0 []
expected differences: 25 ["DCS, split code point after the limit","CSI, split code point after the limit","DCS inside the limit, split code point","CSI, oversized, then SGR 31","CSI, oversized, then erase display","ESC with an intermediate, then U+009B and 6n","CSI, oversized, sets bracketed paste","CSI, oversized, sets application cursor keys","CSI, oversized, sets focus reporting","title cut short by a stripped query","ESC with intermediates, then 6n","ESC, LF, then [6n","CSI, oversized by line feeds, then SGR 31","CSI, seq output, then cursor up","CSI, oversized by DEL, sets bracketed paste","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
replays that sent a reply: 12 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, the base replay replies too: 10 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 4 query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, only this replay replies: 2 ["OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query, cut short by an oversized query"]
only the base replay replies: 0 []

The same streams through other sanitizers

At e37e45fd5b. CSI, never ends differs there because the base holds the whole CSI, so its line feeds never reach history. The three CSI streams oversized by controls match on the base, because the base keeps the whole CSI:

76 streams
unexpected differences: 1 ["CSI, never ends"]
expected differences: 18 ["DCS, split code point after the limit","CSI, split code point after the limit","DCS inside the limit, split code point","ESC with an intermediate, then U+009B and 6n","title cut short by a stripped query","ESC with intermediates, then 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","DCS query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
replays that sent a reply: 10 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 4 query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]

This PR's sanitizer with the ST taken out, so it writes nothing when it drops a sequence. The 9 streams that leave history open before a dropped sequence differ: the 6 listed as unexpected, DCS query behind a LF, cut short by an oversized query, OSC 11 query behind a LF, cut short by an oversized query and OSC 4 query, cut short by an oversized query. 2 of them reply, and only without the ST:

76 streams
unexpected differences: 6 ["ESC cut short, then an oversized OSC, then U+009A","ESC cut short, then an oversized OSC, then U+009B and 6n","ESC cut short, then an oversized OSC, then text","title cut short by an oversized OSC","title cut short by an oversized CSI","charset designation cut short by an oversized OSC"]
expected differences: 26 ["DCS, split code point after the limit","CSI, split code point after the limit","DCS inside the limit, split code point","CSI, oversized, then SGR 31","CSI, oversized, then erase display","ESC with an intermediate, then U+009B and 6n","CSI, oversized, sets bracketed paste","CSI, oversized, sets application cursor keys","CSI, oversized, sets focus reporting","title cut short by a stripped query","ESC with intermediates, then 6n","ESC, LF, then [6n","CSI, oversized by line feeds, then SGR 31","CSI, seq output, then cursor up","CSI, oversized by DEL, sets bracketed paste","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","DCS query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
replays that sent a reply: 12 ["ESC with an intermediate, then U+009B and 6n","ESC cut short, then an oversized OSC, then U+009A","ESC cut short, then an oversized OSC, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 4 query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, the base replay replies too: 10 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 4 query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, only this replay replies: 2 ["ESC cut short, then an oversized OSC, then U+009A","ESC cut short, then an oversized OSC, then U+009B and 6n"]
only the base replay replies: 0 []

A long escape sequence passed through to history instead of cut. The spaces fill what a client keeps, its cut lands inside them, and the replay shows nothing:

## ESC with intermediates past a client's cut
stream 600030 chars, history 0 chars, most held 1 chars
live screen:   ["one","two","three","four","five"] cursor 0,5 red rows [] replies []
replay screen: [] cursor 0,0 red rows [] replies []
input: same, paste "one\rtwo"
scrollback lines: live 5, replay 1
DIFFERENT

76 streams
unexpected differences: 1 ["ESC with intermediates past a client's cut"]
expected differences: 25 ["DCS, split code point after the limit","CSI, split code point after the limit","DCS inside the limit, split code point","CSI, oversized, then SGR 31","CSI, oversized, then erase display","ESC with an intermediate, then U+009B and 6n","CSI, oversized, sets bracketed paste","CSI, oversized, sets application cursor keys","CSI, oversized, sets focus reporting","title cut short by a stripped query","ESC with intermediates, then 6n","ESC, LF, then [6n","CSI, oversized by line feeds, then SGR 31","CSI, seq output, then cursor up","CSI, oversized by DEL, sets bracketed paste","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
replays that sent a reply: 12 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query","OSC 4 query, cut short by an oversized query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, the base replay replies too: 10 ["ESC with an intermediate, then U+009B and 6n","ESC, LF, then [6n","OSC 11 query behind a LF","OSC 4 query","OSC 4 query, cut short by a kept sequence","SOS read as an escape sequence, then U+009B and 6n","OSC 10 query in the second colour slot","OSC 10 query after a colour name","OSC 21 query","CSI 21 t title report"]
of these, only this replay replies: 2 ["OSC 11 query behind a LF, cut short by an oversized query","OSC 4 query, cut short by an oversized query"]
only the base replay replies: 0 []

t3dotgg and others added 30 commits November 21, 2026 03:17
…nd median (pingdotgg#39660)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…efault (pingdotgg#39981)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
… app does (pingdotgg#28597)

Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…rogress (pingdotgg#37859)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…dotgg#38895)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…dotgg#30925)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…t page by default (pingdotgg#40003)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…hanges (pingdotgg#24841)

Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
…tgg#24888)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…s current (pingdotgg#36868)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…checkout (pingdotgg#37191)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
… errors (pingdotgg#40042)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An unfinished control sequence delays all later terminal output